package com.xbongbong.saas.service;

import com.alibaba.fastjson.JSONObject;
import com.xbongbong.paas.domain.entity.ext.PaasFormDataEntityExt;
import com.xbongbong.paas.enums.SheetTypeEnum;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.pojo.FieldAttrEntityForImport;
import com.xbongbong.paas.pojo.dto.AddBatchDTO;
import com.xbongbong.paas.pojo.dto.FormDataAddDTO;
import com.xbongbong.paas.pojo.dto.ImportFormDataDTO;
import com.xbongbong.paas.pojo.dto.SaasFormSaveDTO;
import com.xbongbong.paas.pojo.dto.ValidateDataDTO;
import com.xbongbong.paas.pojo.imports.CellTitlePojo;
import com.xbongbong.paas.pojo.imports.RowGroupPojo;
import com.xbongbong.paas.pojo.vo.FormDataAddVO;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.pro.businessrule.pojo.dto.OperationDTO;
import com.xbongbong.pro.domain.entity.UpdateDataEntity;
import com.xbongbong.pro.formexplain.pojo.dto.HandlerExplainInLinkItemDTO;
import com.xbongbong.pro.listbatch.pojo.dto.AddLabelDTO;
import com.xbongbong.pro.payment.pojo.vo.PaymentInsertBatchVO;
import com.xbongbong.pro.payment.pojo.vo.PaymentUpdateBatchMuchFieldVO;
import com.xbongbong.pro.payplan.pojo.dto.PayPlanBadReturnDTO;
import com.xbongbong.pro.payplan.pojo.dto.PayPlanDTO;
import com.xbongbong.pro.payplan.pojo.dto.PayPlanDeleteBatchDTO;
import com.xbongbong.pro.payplan.pojo.dto.PayPlanEditAttrUpdateDTO;
import com.xbongbong.pro.payplan.pojo.dto.PayPlanInsertBatchDTO;
import com.xbongbong.pro.payplan.pojo.dto.PayPlanUpdateBatchMuchFieldDTO;
import com.xbongbong.pro.payplan.pojo.vo.PayPlanDeleteBatchVO;
import com.xbongbong.pro.payplan.pojo.vo.PayPlanVO;
import com.xbongbong.pro.sheet.pojo.dto.SheetDeleteHandleRelateDTO;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 付款计划业务
 * @author feng.zheng
 * @version v1.0
 * @date 2019/1/18
 * @since v1.0
 */
public interface PayPlanService {
    /**
     * 付款计划保存前saas特殊校验
     *
     * @param validateDataDTO saas特殊校验数据入参
     * @throws XbbException 业务异常
     * @author feng.zheng
     * @date 2019/1/18
     */
    void beforeSave(ValidateDataDTO validateDataDTO) throws XbbException;

    /**
     * 付款计划保存后逻辑
     *
     * @param saasFormSaveDTO saas保存数据
     * @throws XbbException 业务异常
     * @author feng.zheng
     */
    void afterSave(SaasFormSaveDTO saasFormSaveDTO) throws XbbException;



    /**
     * 付款
     * @author 吴峰
     * @date 2019/2/12 16:28
     * @param payPlanDTO
     * @return com.xbongbong.pro.payment.pojo.vo.PaymentVO
     * @throws XbbException
     */
    FormDataAddVO payPlan(PayPlanDTO payPlanDTO) throws XbbException;
    /**
     * 批量判断编号是否重复，以及判断金额
     * @author 吴峰
     * @date 2019/2/14 11:09
     * @param payPlanDTO
     * @return void
     * @throws XbbException
     */
    void repeatBatch(PayPlanDTO payPlanDTO) throws XbbException;

    /**
     * 批量保存
     * @param payPlanInsertBatchDTO
     * @param parentNew
     * @throws XbbException
     */
    PaymentInsertBatchVO insertBatch(PayPlanInsertBatchDTO payPlanInsertBatchDTO, Boolean parentNew, String creatorId) throws XbbException;

    /**
     * 批量更新多个字段
     * @param payPlanUpdateBatchMuchFieldDTO
     * @param source 用以标记日志的来源，true：付款计划普通编辑，false：付款计划批量编辑
     * @throws XbbException
     */
    PaymentUpdateBatchMuchFieldVO updateBatchMuchField(PayPlanUpdateBatchMuchFieldDTO payPlanUpdateBatchMuchFieldDTO, boolean source, Map<String, FieldAttrEntity> explainMap) throws XbbException;

    /**
     * 批量删除
     * @author 吴峰
     * @date 2019/2/14 14:50
     * @param paymentDeleteBatchDTO
     * @return com.xbongbong.pro.payment.pojo.vo.PaymentDeleteBatchVO
     * @throws XbbException
     */
    PayPlanDeleteBatchVO deleteBatch(PayPlanDeleteBatchDTO paymentDeleteBatchDTO) throws XbbException;

    /**
     * 根据采购合同id批量删除
     * @param payPlanDeleteBatchDTO
     * @return
     * @throws XbbException
     */
    PayPlanDeleteBatchVO deleteBatchByPurchaseId(PayPlanDeleteBatchDTO payPlanDeleteBatchDTO) throws XbbException;
    /**
     *
     * @param formDataSaveDTO
     * @return
     * @throws XbbException
     */
    AddBatchDTO beforeSaveBatch(FormDataAddDTO formDataSaveDTO, boolean fromApproval) throws XbbException;

    /**
     * 判断付款的付款单是否有在审批中
     *
     * @param payPlanId 付款计划id
     * @param corpid    公司id
     * @return 创建时间： 2017-12-14 下午9:32:20
     * 修改时间：
     * @author chy
     */
    boolean payPlanApproval(Long payPlanId, String corpid);
    /**
     * 批量编辑某个字段
     * @author 吴峰
     * @date 2019/3/20 14:40
     * @param payPlanEditAttrUpdateDTO
     * @return void
     * @throws XbbException 业务异常
     */
    void batchEditAttr(PayPlanEditAttrUpdateDTO payPlanEditAttrUpdateDTO) throws XbbException;

    /**
     * 获取采购合同关联的付款计划
     *
     * @param  corpid       公司id
     * @param  purchaseId   采购合同id
     * @author GuoJun.HU
     * @since V1.0
     * @return List
     * @date 2019/4/11 14:03
     */
    List<PaasFormDataEntityExt> getPayPlanEsDataListByPurchaseId(String corpid, Long purchaseId) throws XbbException;

    void formatLinkAddExplain(HandlerExplainInLinkItemDTO handlerExplainInLinkItemDTO) throws XbbException;

    /**
     * 修改供应商名称
     * @author 吴峰
     * @date 2019/6/20 10:54
     * @param corpid 公司id
     * @param dataId 数据id
     * @param name 供应商名称
     * @return void
     * @throws XbbException 业务异常
     */
    void dataConsistencyUpdateSupplier(String corpid, Long dataId, String name) throws XbbException;

    /**
     * 业务规则之修改某些字段数据
     * @param operationDTO
     * @throws XbbException
     */
    void updateBatchByBusinessRule(OperationDTO operationDTO) throws XbbException;

    /**
     * 坏账还原
     * @param payPlanBadReturnDTO
     * @return
     * @throws XbbException
     */
    PayPlanVO badDebtReturn(PayPlanBadReturnDTO payPlanBadReturnDTO) throws XbbException;

    /**
     * 创建付款单时，处理付款计划并封装要更新的结果：
     * （1）判断已付金额是否已经超过付款计划内的未付金额，并把付款计划的已付金额增加及更改其付款状态等
     * （2）处理付款金额、核销金额
     * （3）把红冲的付款金额置为负数
     * 已核销、预付款核销：已付金额增加，未付减少，限制付款金额小于计划的未付
     * @param sheetTypeEnum 回/付款单类型
     * @param sheetData 付款单（父级，级外层总的）data
     * @param corpid 公司id
     * @param paymentIdToAmount 计划id-该计划对应的回款金额
     * @param paymentIds 计划ids
     * @return java.util.List<com.xbongbong.saas.domain.entity.ext.PaymentEntityExt>
     * @throws XbbException
     * @author zcp
     * @since v1.0
     * @version v1.0
     */
    List<UpdateDataEntity> handlePlan(SheetTypeEnum sheetTypeEnum, JSONObject sheetData, String corpid, Map<Long, Double> paymentIdToAmount, Set<Long> paymentIds) throws XbbException;

    /**
     * Description: 格式化导出excelvalue
     * @param importFormDataDTO 入参
     * @param titlePojoList 标题
     * @param rowGroupPojo 组
     * @param fieldAttrList 解释
     * @return FormDataAddDTO
     * @author chenshan
     * @date 2020/3/10 16:47
     * @since v1.0
     */
    FormDataAddDTO formatExcelValue(ImportFormDataDTO importFormDataDTO, List<CellTitlePojo> titlePojoList, RowGroupPojo rowGroupPojo, List<FieldAttrEntityForImport> fieldAttrList) throws XbbException;

    /**
     * 更新回滚es
     * @param idIn
     * @param corpid
     * @throws XbbException
     */
    void updateRollback(Collection<Long> idIn, String corpid) throws XbbException;
    /**
     * 删除付款单时，同步更新付款计划
     * @param corpid 公司id
     * @param errorTypeSet 不允许删除类型
     * @param errorDataSet 不允许删除数据
     * @param allDelIdList 所有要删除的付款单id集合（因为重置更新付款计划的时间时，需要查询除allDelIdList之外的付款单）
     * @param sheetDeleteHandleRelateDTO 删除/批量删除付款单，更新其关联业务（供应商、采购合同、付款计划）dto
     * @return java.util.List<com.xbongbong.pro.domain.entity.UpdateDataEntity>
     * @throws XbbException
     * @author zcp
     * @date 19/12/6 006 21:21
     * @update 19/12/6 006 21:21
     * @since v1.0
     * @version v1.0
     */
    List<UpdateDataEntity> updatePlan4Del(String corpid, Set<String> errorTypeSet, Set<String> errorDataSet, Collection<Long> allDelIdList, SheetDeleteHandleRelateDTO sheetDeleteHandleRelateDTO) throws XbbException;

    void updateBatchLabelAttr(AddLabelDTO addLabelDTO, List<PaasFormDataEntityExt> addBatchList, Boolean addOrDelete) throws XbbException;

    void afterSaveForWorkflow(SaasFormSaveDTO saasFormSaveDTO) throws XbbException;

    void afterSaveForUpdateWorkflow(SaasFormSaveDTO saasFormSaveDTO);
}
